//
//  HELLocationHeader.m
//  sanda
//
//  Created by wsj2015 on 16/9/23.
//  Copyright © 2016年 陈武琦. All rights reserved.
//

#import "HELLocationHeader.h"
#import "CWQ_locationTool.h"
@implementation HELLocationHeader


+ (instancetype)locationHeadView{
    
    return [[NSBundle mainBundle] loadNibNamed:@"HELLocationHeader" owner:nil options:0].lastObject;
    
}
- (IBAction)reloactionAction:(id)sender {
    
  
    
     self.relocationBtn.alpha = 0;
     [self.activeView startAnimating];
//    [self startLoactionWithCallBack:<#^(NSString *)callback#>]
    [self  startLoaction];
   
    
}

- (void)startLoaction{
   
    weakSelf_define;
    //开始定位中
    self.statue = 0;
    

    [[CWQ_locationTool manager] locationSuccess:^(NSString *address, double latitude, double longitude) {
    
        weakSelf.statue = 1;
        if (!address) {
            return ;
        }
        
        weakSelf.locaitonL.text = [NSString stringWithFormat:@"当前位置:%@",address];
        if (self.observeAddressBlock) {
            self.observeAddressBlock(@{@"address_address":address,@"address_lat":@(latitude),@"address_long":@(longitude)});
        }
        weakSelf.relocationBtn.alpha = 1.0f;
        [weakSelf.activeView stopAnimating];
       
    } failure:^(NSString *reason) {
        weakSelf.statue = -1;
        if (self.observeAddressBlock) {
            self.observeAddressBlock(nil);
        }
         weakSelf.relocationBtn.alpha = 1;
         weakSelf.locaitonL.text = [NSString stringWithFormat:@"定位失败"];
         [weakSelf.activeView startAnimating];
    }];

}
@end
